package com.oppo.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.oppo.bean.UserBean;
import com.oppo.service.impl.FindImgService;
import com.oppo.tools.MyTools;


@WebServlet("/FindImgControl")
public class FindImgControl extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		UserBean one = new UserBean();
		String user_id = request.getSession().getAttribute("user_id").toString();//= request.getParameter("user_id");
		one.setUser_id(new Long(user_id));
		
		List<UserBean> list = MyTools.getNewInstance(FindImgService.class).jsonOfQuery(one);
		
		// 借助第三方的工具将集合转换为json字符串【alibaba的fastjson插件包】
		// 将查询结果集list转换为json字符串
		String strJson = JSON.toJSONStringWithDateFormat(list, "yyyy-MM-dd");
		// ajax响应
		// 响应客户单的请求
		PrintWriter pw = response.getWriter();
		// 将json字符串发回客户端浏览器
		pw.write(strJson);
		pw.flush();
		pw.close();
	}

}
